<template>
  <div class="box">
  	<div class="cppj">
  		<h4>为菜品打分</h4>
  		<ul>
  			<li v-for="food in foods">
  				<div class="pjtopbox">
  					<img :src="food.imgurl" />
	  				<div class="xj">
			  			<span class="star-item" :class="[item<=food.curId?'on':'']" v-for="item in stararr" @click="food.curId=item">★&nbsp;</span>
			  		</div>
  				</div>  				
		  		<textarea placeholder="写下您对菜品的评价吧~" v-model="food.content"></textarea>
 
  			</li>
  			
  		</ul>
  		 		
  	</div>
  	<div class="sjpj">
  		<h4>为商家打分</h4>
  		<div class="xj">
  			<span class="star-item" :class="[item<=sjcurId?'on':'']" v-for="item in stararr" @click="sjsetStar(item)">★&nbsp;</span>
  		</div>
  		<textarea placeholder="写下您对商家的评价吧~" v-model="sjcontent"></textarea>
  		
  	</div>
  	<div class="tj"><i @click="onSubmit">提交</i></div>
  </div>
</template>

<script >
import axios from "axios"
export default { 
  data () {
    return {
     stararr: [1,2,3,4,5],
     foods:[{id:0,imgurl:'static/images/banner1.jpg',content:'',curId:0},{id:1,imgurl:'static/images/banner1.jpg',content:'',curId:0}],      
      sjcurId:0,
      sjcontent: '',      
      errmsg:'',
      pinglun:{}
    }
  },
   methods: {  	
   	sjsetStar(id) {     
      this.sjcurId = id;
    },
    onSubmit() {
    	this.pinglun.xj=this.curId;
    	this.pinglun.nr=this.content;
    	var self = this;
      if (this.curId===0) {
          this.errmsg = '请先选择星级！';
          alert(this.errmsg);
          return;
      }else {
        this.errmsg = '';
      }
      if (this.content==='') {
        this.errmsg = '评价内容不能为空！';
        alert(this.errmsg);
        return;
      }else {
        this.errmsg = '';
      } 
     
     axios({
     	type:"post",
     	url:'pinglun',
     	contentType:"application/json",
     	data:JSON.stringify( this.pinglun ),
     	success: function(r){
	        if(r === ''){
	            alert('操作成功', function(){
	                //刷新当前页面
	            });
	        }else{
	            alert('');
	        }
	    }

     	
     })
     
    }
   }
}
</script>


<style scoped src="../assets/css/pingjiasj.css"></style>
